<template>
  <div class="login-wrap">
    <div class="ms-login">
      <div class="ms-title">企业培训系统注册页面</div>
      <el-form :model="param"
               :rules="rules"
               ref="login"
               label-width="0px"
               class="ms-content"
               inline="true"
               :size="size">
        <!-- 账号 -->
        <el-form-item prop="account">
          <el-input v-model="param.account"
                    placeholder="account">
            <el-button slot="prepend"
                       icon="el-icon-lx-people"></el-button>
          </el-input>
        </el-form-item>
        <!-- 密码 -->
        <el-form-item prop="password">
          <el-input type="password"
                    placeholder="password"
                    v-model="param.password"
                    @keyup.enter.native="submitForm()">
            <el-button slot="prepend"
                       icon="el-icon-lx-lock"></el-button>
          </el-input>
        </el-form-item>
        <!-- 再次密码 -->
        <el-form-item prop="password">
          <el-input type="password"
                    placeholder="password"
                    v-model="param.password1"
                    @keyup.enter.native="submitForm()">
            <el-button slot="prepend"
                       icon="el-icon-lx-lock"></el-button>
          </el-input>
        </el-form-item>

        <!-- 性别 -->
        <el-form-item prop="sex">
          <el-select v-model="param.sex"
                     placeholder="性别">
            <el-option label="男"
                       value="男"></el-option>
            <el-option label="女"
                       value="女"></el-option>
          </el-select>
        </el-form-item>

        <!-- 部门 -->
        <el-form-item prop="department">
          <el-select v-model="param.department"
                     placeholder="部门">
            <el-option label="咨询部"
                       value="咨询部"></el-option>
            <el-option label="教学部"
                       value="教学部"></el-option>
          </el-select>
        </el-form-item>
        <!-- 电话 -->
        <el-form-item prop="telphone">
          <el-input v-model="param.telphone"
                    placeholder="telphone">
            <el-button slot="prepend"
                       icon="el-icon-lx-people"></el-button>
          </el-input>
        </el-form-item>
        <!-- 邮箱 -->
        <el-form-item prop="email">
          <el-input v-model="param.email"
                    placeholder="邮箱">
            <el-button slot="prepend"
                       icon="el-icon-lx-people"></el-button>
          </el-input>
        </el-form-item>

        <div class="login-btn">

          <el-button type="primary"
                     @click="register()">注册</el-button>

        </div>

      </el-form>
    </div>
  </div>
</template>

<script>
export default {
     
    data: function () {
        return {
          FloatRegex : /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/,
          FloatRegex1:/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
            rememberpwd: false,

            param: {
                account: '',
                password: '',
                sex: '',
                department: '',
                telphone: '',
                email: ''
            },
            rules: {
                account: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
                telphone: [
                    {
                        required: true,
                        message: '请输入正确的联系方式',
                        pattern: /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/,
                        trigger: 'blur'
                    }
                ],
                email: [
                    {
                        required: true,
                        message: '请输入正确的邮箱格式',
                        pattern: /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
                        trigger: 'blur'
                    }
                ]
            }
        };  
    },
    methods: {
        register() {
            // console.log(this.param);
            console.log(this.param.account);
            if (
                this.param.password == this.param.password1 &&
                this.param.account != '' &&
                this.FloatRegex.test(this.param.telphone) &&
                this.FloatRegex1.test(this.param.email)
            ) {
                console.log(this.param);
                this.$axios.post('/api/users/addUsers', this.param).then((res) => {
                    if (res.data.code == 200) {
                        console.log(res);
                        this.$router.push('/Login');
                    }
                });
            } else {
                alert('输入格式不正确');
            }
        }
    }
};
</script>

<style scoped>
.login-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    background-image: url(../../assets/img/login-bg.jpg);
    background-size: 100%;
}
.ms-title {
    width: 100%;
    line-height: 50px;
    text-align: center;
    font-size: 20px;
    color: #fff;
    border-bottom: 1px solid #ddd;
}
.ms-login {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 350px;
    margin: -190px 0 0 -175px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.3);
    overflow: hidden;
}
.ms-content {
    padding: 30px 30px;
}
.login-btn {
    text-align: center;
}
.login-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
}
.login-tips {
    font-size: 12px;
    line-height: 30px;
    color: #fff;
}
</style>